<template>
  <div class="index">
    <el-container>
      <el-header>
        <h1>后台管理系统</h1>
        <el-dropdown @command="loginout" trigger="click">
          <span class="el-dropdown-link">
            {{ menuList.username }}
            <el-icon class="el-icon--right">
              <arrow-down />
            </el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item>退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-menu active-text-color="#ffd04b" background-color="#545c64" class="el-menu-vertical-demo"
            :default-active="route.path" text-color="#fff" router>
            <el-menu-item index="/home">
              <el-icon>
                <House />
              </el-icon>
              <span>首页</span>
            </el-menu-item>
            <el-sub-menu :index="item.id" v-for="item in menuList.menus" :key="item.id">
              <template #title>
                <el-icon>
                  <component :is="item.icon"></component>
                </el-icon>
                <span>{{ item.title }}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item v-for="item2 in item.children" :key="item2.id" :index="item2.url">{{ item2.title
                }}</el-menu-item>
              </el-menu-item-group>
            </el-sub-menu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script lang="ts" setup>
import { ElMessage } from "element-plus";
import { useRouter, useRoute } from 'vue-router';

let userInfo: any = sessionStorage.getItem("userInfo");
let menuList = JSON.parse(userInfo);
let router = useRouter();
let route = useRoute();

function loginout() {
  sessionStorage.removeItem('userInfo');
  ElMessage.success('退出成功');
  router.push('/login');
}
</script>

<style scoped>
.index,
.el-container {
  width: 100%;
  height: 100%;
}

.el-header {
  background: skyblue;
}

.el-main {
  background: azure;
}

.is-active {
  background: dimgray;
}

.el-header {
  position: relative;
}

.el-dropdown {
  cursor: pointer;
  position: absolute;
  right: 30px;
  top: 20px;
}

.el-menu {
  height: 100%;
}

h1 {
  text-align: center;
  padding-top: 13px;
}
</style>